class ChangePasswordController {
    def authenticateService

    def index = { 
        redirect action: changePassword
    }
    def changePassword = { }
 
     def saveChangePassword = {
        def person = User.get(authenticateService.userDomain().id)
        if(person.passwd == authenticateService.encodePassword(params.oldPassword)){
            if (params.passwd.equals(params.confirmPasswd)) {
			    person.passwd = authenticateService.encodePassword(params.passwd)
                if (person.save()) {
                    flash.message = "密码修改成功"
                    redirect action: changePassword
                }else {
                    return render(view:"changePassword")
                }
		    }else{
                person.errors.rejectValue('passwd','新密码与确认密码不相同')
                return render(view:"changePassword",model:[person:person])
            }
        }else{
            person.errors.rejectValue('passwd','原密码不正确')
            return render(view:"changePassword",model:[person:person])
        }
     }
}
